import CryptoJS from './crypto-js.js';

function secret(string, operation) {
	var code = 'hjiajia0520';
	code = CryptoJS.MD5(code).toString();
	var iv = CryptoJS.enc.Utf8.parse(code.substring(0, 16));
	var key = CryptoJS.enc.Utf8.parse(code.substring(16));
	if (operation) {
		return CryptoJS.AES.decrypt(string, key, {
			iv: iv,
			padding: CryptoJS.pad.Pkcs7
		}).toString(CryptoJS.enc.Utf8);
	}
	return CryptoJS.AES.encrypt(string, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.Pkcs7
	}).toString();
}

function _md5(string) {
	return CryptoJS.MD5(string).toString();
}

module.exports = {
	secret: secret,
	_md5: _md5
}
